package com.ruyuan.common.model;

import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author xx
 */
@Data
public class PageDTO<T> implements Serializable {

    private static final long serialVersionUID = 5614059081595218964L;

    private List<T> data;

    private int current;

    private int pageSize;

    private int curPageSize;

    //总记录数
    private Long total;

    //总页数
    private int pages;

    public static <T> PageDTO<T> of(PageDTO pageDTO, List<T> data) {
        PageDTO<T> result = new PageDTO<>();
        result.setData(data);
        result.setPages(pageDTO.getPages());
        result.setCurrent(pageDTO.getCurrent());
        result.setCurPageSize(pageDTO.getCurPageSize());
        result.setPageSize(pageDTO.getPageSize());
        result.setTotal(pageDTO.getTotal());
        return result;
    }

    public static <T> PageDTO<T> emptyPage(Integer pageSize){
        PageDTO<T> result = new PageDTO<>();
        result.setData(new ArrayList<T>());
        result.setPages(0);
        result.setCurrent(1);
        result.setPageSize(pageSize);
        result.setCurPageSize(0);
        result.setTotal(0L);
        return result;
    }

}
